/**
 * @(#) AppmssProxy.as
 *
 * @date		2011. 03. 25
 * @version		1.0
 * @author		baek kwang hyoun
 * @description	평가결과 Proxy - Proxy
 */
package com.skt.common_hr.empcont.model
{
	import com.skt.common_hr.common.puremvc.CommonProxy;
	import com.skt.common_hr.empcont.model.vo.PayTableVO;
	import com.skt.common_hr.empcont.model.vo.mainListVO;
	import com.wcl.utils.DateUtil;
	import com.wcl.utils.NumberUtil;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	

	public class PayTableProxy extends CommonProxy
	{
		public static const NAME:String = "PayTableProxy";
		
		public var mainList:ArrayCollection;
		/**
		 * 생성자
		 *
		 * @param
		 * @return void
		 */
		public function PayTableProxy(data:Object=null)
		{
			super(NAME, data);
		}

		
		public function loadList(vo:mainListVO, setFunc:Function):void
		{
			var obj:Object = {};
			obj.I_ZYEAR = vo.ZYEAR;

			loadData("Z_HR_EC05", obj, loadListResult, listFault, setFunc);
		}
		
		public function loadListResult(event:ResultEvent):void
		{
			if(retCode==0) {							
				mainList = parseMainList(event.result.OTAB);
				
				var rtnObj:Object =  {};
				rtnObj.mainList = mainList;
				
				event.result.func(rtnObj);
			}
			else {
				Alert.show(retText);
			}
		}
		
		private function listFault(event:FaultEvent):void
		{
			Alert.show('HthIcProxy.as listFault err: ' + retText);
		}
			
		private function parseMainList(recArr:ArrayCollection):ArrayCollection
		{
			var retArr:ArrayCollection = new ArrayCollection();
		
			for each(var obj:Object in recArr){
				var retObj:PayTableVO = new PayTableVO();  
		
				for(var field:String in obj) {
				if(retObj.hasOwnProperty(field)==false ) {
				continue;
				}
		     
				if(field == "SDATE") {
					retObj[field] = DateUtil.stringToDateTime(obj[field]);
					retObj[field+'_TX'] = DateUtil.toDefaultString(retObj[field]);
					retObj[field+'_JSON'] = DateUtil.toBasicString(retObj[field]);
				}
				else if(field == "BETRG" ) {
					retObj[field+'_TX'] = NumberUtil.NumberFormat(Math.round(obj[field]*100));
				}            
				else {      
					retObj[field] = obj[field];
				}
			}
		retArr.addItem(retObj);
		}
		return retArr;
		}
	}		
}